#!/bin/bash
echo "========1. Dropping previous 0.1 database..."
/usr/lib/postgresql/8.3/bin/dropdb -h localhost -p 5132 tpch01

echo "========2. Dropping previous 0.01 database..."
/usr/lib/postgresql/8.3/bin/dropdb -h localhost -p 5132 tpch001

echo "========3. Creating new 0.1 database..."
/usr/lib/postgresql/8.3/bin/createdb -h localhost -p 5132 tpch01

echo "========4. Creating new 0.01 database..."
/usr/lib/postgresql/8.3/bin/createdb -h localhost -p 5132 tpch001

echo "========5. Importing table structure to 0.1..."
/usr/lib/postgresql/8.3/bin/psql -h localhost -p 5132 tpch01 < /local/group3705/dbgen/dss.ddl

echo "========6. Importing table structure to 0.01..."
/usr/lib/postgresql/8.3/bin/psql -h localhost -p 5132 tpch001 < /local/group3705/dbgen/dss.ddl

echo "========7. Creating the user and granting to 0.1..."
/usr/lib/postgresql/8.3/bin/psql -h localhost -p 5132 tpch01 < /local/group3705/server/create_grant01.sql

echo "========8. Creating the user and granting to 0.01..."
/usr/lib/postgresql/8.3/bin/psql -h localhost -p 5132 tpch001 < /local/group3705/server/create_grant001.sql

echo "========9. Generating the 0.1 database..."
cd /local/group3705/dbgen
./dbgen -f -v -s 0.1

echo "========10. Removing trailing | chars from 0.1..."
/local/group3705/server/remove_trailing.sh

echo "========11. Importing generated 0.1 database..."
/usr/lib/postgresql/8.3/bin/psql -h localhost -p 5132 tpch01 < /local/group3705/server/table_copy.sql

echo "========12. Generating the 0.01 database..."
cd /local/group3705/dbgen
./dbgen -f -v -s 0.01

echo "========13. Removing trailing | chars from 0.01..."
/local/group3705/server/remove_trailing.sh

echo "========14. Importing generated 0.01 database..."
/usr/lib/postgresql/8.3/bin/psql -h localhost -p 5132 tpch001 < /local/group3705/server/table_copy.sql
